<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" type="text/css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" type="text/css">
    <link rel="stylesheet" href="./resources/prism/prism.css" type="text/css">
    <link rel="stylesheet" href="../css/ol.css" type="text/css">
    <link rel="stylesheet" href="./resources/layout.css" type="text/css">
    <script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js"></script>
    
    <script src="./resources/zeroclipboard/ZeroClipboard.min.js"></script>
    <title>Raster reprojection example</title>
  </head>
  <body>

    <header class="navbar" role="navigation">
      <div class="container" id="navbar-inner-container">
        <a class="navbar-brand" href="./"><img src="./resources/logo-70x70.png">&nbsp;OpenLayers 3 Examples</a>
      </div>
    </header>

    <div class="container-fluid">

      <div class="row-fluid">
  <div class="span12">
    <div id="map" class="map"></div>
  </div>
  <form class="form-inline">
    <div class="col-md-3">
      <label>Base map:</label>
      <select id="base-layer">
        <option value="mapquest">MapQuest (EPSG:3857)</option>
        <option value="wms4326">WMS (EPSG:4326)</option>
      </select>
    </div>
    <div class="col-md-4">
      <label>Overlay map:</label>
      <select id="overlay-layer">
        <option value="bng">British National Grid (EPSG:27700)</option>
        <option value="wms21781">Swisstopo WMS (EPSG:21781)</option>
        <option value="wmts3413">NASA Arctic WMTS (EPSG:3413)</option>
        <option value="grandcanyon">Grand Canyon HiDPI (EPSG:3857)</option>
        <option value="states">United States (EPSG:3857)</option>
      </select>
    </div>
    <div class="col-md-5">
      <label>View projection:</label>
      <select id="view-projection">
        <option value="EPSG:3857">Spherical Mercator (EPSG:3857)</option>
        <option value="EPSG:4326">WGS 84 (EPSG:4326)</option>
        <option value="ESRI:54009">Mollweide (ESRI:54009)</option>
        <option value="EPSG:27700">British National Grid (EPSG:27700)</option>
        <option value="EPSG:23032">ED50 / UTM zone 32N (EPSG:23032)</option>
        <option value="EPSG:2163">US National Atlas Equal Area (EPSG:2163)</option>
        <option value="EPSG:3413">NSIDC Polar Stereographic North (EPSG:3413)</option>
        <option value="EPSG:5479">RSRGD2000 / MSLC2000 (EPSG:5479)</option>
      </select>
    </div>
    <label for="render-edges"><input type="checkbox" id="render-edges" />Render reprojection edges</label> (only displayed on reprojected data)
  </form>
</div>


      <div class="row-fluid">
        <div class="span12">
          <h4 id="title">Raster reprojection example</h4>
          <p id="shortdesc">Demonstrates client-side raster reprojection between various projections.</p>
          <div id="docs"><p>This example shows client-side raster reprojection between various projections.</p>
</div>
          <div id="tags">reprojection, projection, proj4js, mapquest, wms, wmts, hidpi</div>
          <div id="api-links">Related API documentation: <ul class="inline"><li><a href="../apidoc/ol.Attribution.html" title="API documentation for ol.Attribution">ol.Attribution</a></li>,<li><a href="../apidoc/ol.Map.html" title="API documentation for ol.Map">ol.Map</a></li>,<li><a href="../apidoc/ol.View.html" title="API documentation for ol.View">ol.View</a></li>,<li><a href="../apidoc/ol.extent.html" title="API documentation for ol.extent">ol.extent</a></li>,<li><a href="../apidoc/ol.format.WMTSCapabilities.html" title="API documentation for ol.format.WMTSCapabilities">ol.format.WMTSCapabilities</a></li>,<li><a href="../apidoc/ol.layer.Tile.html" title="API documentation for ol.layer.Tile">ol.layer.Tile</a></li>,<li><a href="../apidoc/ol.proj.html" title="API documentation for ol.proj">ol.proj</a></li>,<li><a href="../apidoc/ol.source.MapQuest.html" title="API documentation for ol.source.MapQuest">ol.source.MapQuest</a></li>,<li><a href="../apidoc/ol.source.TileImage.html" title="API documentation for ol.source.TileImage">ol.source.TileImage</a></li>,<li><a href="../apidoc/ol.source.TileWMS.html" title="API documentation for ol.source.TileWMS">ol.source.TileWMS</a></li>,<li><a href="../apidoc/ol.source.WMTS.html" title="API documentation for ol.source.WMTS">ol.source.WMTS</a></li>,<li><a href="../apidoc/ol.source.XYZ.html" title="API documentation for ol.source.XYZ">ol.source.XYZ</a></li>,<li><a href="../apidoc/ol.tilegrid.TileGrid.html" title="API documentation for ol.tilegrid.TileGrid">ol.tilegrid.TileGrid</a></li></ul></div>
        </div>
      </div>

      <div class="row-fluid">
        <div id="source-controls">
          <a id="copy-button"><i class="fa fa-clipboard"></i> Copy</a>
          <a id="jsfiddle-button"><i class="fa fa-jsfiddle"></i> Edit</a>
        </div>
        <form method="POST" id="jsfiddle-form" target="_blank" action="http://jsfiddle.net/api/post/jquery/1.11.0/">
          <textarea class="hidden" name="js">proj4.defs(&#x27;EPSG:27700&#x27;, &#x27;+proj&#x3D;tmerc +lat_0&#x3D;49 +lon_0&#x3D;-2 +k&#x3D;0.9996012717 &#x27; +
    &#x27;+x_0&#x3D;400000 +y_0&#x3D;-100000 +ellps&#x3D;airy &#x27; +
    &#x27;+towgs84&#x3D;446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 &#x27; +
    &#x27;+units&#x3D;m +no_defs&#x27;);
var proj27700 &#x3D; ol.proj.get(&#x27;EPSG:27700&#x27;);
proj27700.setExtent([0, 0, 700000, 1300000]);

proj4.defs(&#x27;EPSG:23032&#x27;, &#x27;+proj&#x3D;utm +zone&#x3D;32 +ellps&#x3D;intl &#x27; +
    &#x27;+towgs84&#x3D;-87,-98,-121,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj23032 &#x3D; ol.proj.get(&#x27;EPSG:23032&#x27;);
proj23032.setExtent([-1206118.71, 4021309.92, 1295389.00, 8051813.28]);

proj4.defs(&#x27;EPSG:5479&#x27;, &#x27;+proj&#x3D;lcc +lat_1&#x3D;-76.66666666666667 +lat_2&#x3D;&#x27; +
    &#x27;-79.33333333333333 +lat_0&#x3D;-78 +lon_0&#x3D;163 +x_0&#x3D;7000000 +y_0&#x3D;5000000 &#x27; +
    &#x27;+ellps&#x3D;GRS80 +towgs84&#x3D;0,0,0,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj5479 &#x3D; ol.proj.get(&#x27;EPSG:5479&#x27;);
proj5479.setExtent([6825737.53, 4189159.80, 9633741.96, 5782472.71]);

proj4.defs(&#x27;EPSG:21781&#x27;, &#x27;+proj&#x3D;somerc +lat_0&#x3D;46.95240555555556 &#x27; +
    &#x27;+lon_0&#x3D;7.439583333333333 +k_0&#x3D;1 +x_0&#x3D;600000 +y_0&#x3D;200000 +ellps&#x3D;bessel &#x27; +
    &#x27;+towgs84&#x3D;674.4,15.1,405.3,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj21781 &#x3D; ol.proj.get(&#x27;EPSG:21781&#x27;);
proj21781.setExtent([485071.54, 75346.36, 828515.78, 299941.84]);

proj4.defs(&#x27;EPSG:3413&#x27;, &#x27;+proj&#x3D;stere +lat_0&#x3D;90 +lat_ts&#x3D;70 +lon_0&#x3D;-45 +k&#x3D;1 &#x27; +
    &#x27;+x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 +units&#x3D;m +no_defs&#x27;);
var proj3413 &#x3D; ol.proj.get(&#x27;EPSG:3413&#x27;);
proj3413.setExtent([-4194304, -4194304, 4194304, 4194304]);

proj4.defs(&#x27;EPSG:2163&#x27;, &#x27;+proj&#x3D;laea +lat_0&#x3D;45 +lon_0&#x3D;-100 +x_0&#x3D;0 +y_0&#x3D;0 &#x27; +
    &#x27;+a&#x3D;6370997 +b&#x3D;6370997 +units&#x3D;m +no_defs&#x27;);
var proj2163 &#x3D; ol.proj.get(&#x27;EPSG:2163&#x27;);
proj2163.setExtent([-8040784.5135, -2577524.9210, 3668901.4484, 4785105.1096]);

proj4.defs(&#x27;ESRI:54009&#x27;, &#x27;+proj&#x3D;moll +lon_0&#x3D;0 +x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 &#x27; +
    &#x27;+units&#x3D;m +no_defs&#x27;);
var proj54009 &#x3D; ol.proj.get(&#x27;ESRI:54009&#x27;);
proj54009.setExtent([-18e6, -9e6, 18e6, 9e6]);


var layers &#x3D; [];

layers[&#x27;bng&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.XYZ({
    projection: &#x27;EPSG:27700&#x27;,
    url: &#x27;http://tileserver.maptiler.com/miniscale/{z}/{x}/{y}.png&#x27;,
    crossOrigin: &#x27;&#x27;,
    maxZoom: 6
  })
});

layers[&#x27;mapquest&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.MapQuest({layer: &#x27;osm&#x27;})
});

layers[&#x27;wms4326&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: &#x27;http://demo.boundlessgeo.com/geoserver/wms&#x27;,
    crossOrigin: &#x27;&#x27;,
    params: {
      &#x27;LAYERS&#x27;: &#x27;ne:NE1_HR_LC_SR_W_DR&#x27;
    },
    projection: &#x27;EPSG:4326&#x27;
  })
});

layers[&#x27;wms21781&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    attributions: [new ol.Attribution({
      html: &#x27;&amp;copy; &#x27; +
          &#x27;&lt;a href&#x3D;&quot;http://www.geo.admin.ch/internet/geoportal/&#x27; +
          &#x27;en/home.html&quot;&gt;&#x27; +
          &#x27;Pixelmap 1:1000000 / geo.admin.ch&lt;/a&gt;&#x27;
    })],
    crossOrigin: &#x27;anonymous&#x27;,
    params: {
      &#x27;LAYERS&#x27;: &#x27;ch.swisstopo.pixelkarte-farbe-pk1000.noscale&#x27;,
      &#x27;FORMAT&#x27;: &#x27;image/jpeg&#x27;
    },
    url: &#x27;http://wms.geo.admin.ch/&#x27;,
    projection: &#x27;EPSG:21781&#x27;
  })
});

var parser &#x3D; new ol.format.WMTSCapabilities();
$.ajax(&#x27;http://map1.vis.earthdata.nasa.gov/wmts-arctic/&#x27; +
    &#x27;wmts.cgi?SERVICE&#x3D;WMTS&amp;request&#x3D;GetCapabilities&#x27;).then(function(response) {
  var result &#x3D; parser.read(response);
  var options &#x3D; ol.source.WMTS.optionsFromCapabilities(result,
      {layer: &#x27;OSM_Land_Mask&#x27;, matrixSet: &#x27;EPSG3413_250m&#x27;});
  options.crossOrigin &#x3D; &#x27;&#x27;;
  options.projection &#x3D; &#x27;EPSG:3413&#x27;;
  options.wrapX &#x3D; false;
  layers[&#x27;wmts3413&#x27;] &#x3D; new ol.layer.Tile({
    source: new ol.source.WMTS(options)
  });
});

layers[&#x27;grandcanyon&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.XYZ({
    url: &#x27;http://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png&#x27;,
    crossOrigin: &#x27;&#x27;,
    tilePixelRatio: 2,
    maxZoom: 15,
    attributions: [new ol.Attribution({
      html: &#x27;Tiles &amp;copy; USGS, rendered with &#x27; +
          &#x27;&lt;a href&#x3D;&quot;http://www.maptiler.com/&quot;&gt;MapTiler&lt;/a&gt;&#x27;
    })]
  })
});

var startResolution &#x3D;
    ol.extent.getWidth(ol.proj.get(&#x27;EPSG:3857&#x27;).getExtent()) / 256;
var resolutions &#x3D; new Array(22);
for (var i &#x3D; 0, ii &#x3D; resolutions.length; i &lt; ii; ++i) {
  resolutions[i] &#x3D; startResolution / Math.pow(2, i);
}

layers[&#x27;states&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: &#x27;http://demo.boundlessgeo.com/geoserver/wms&#x27;,
    crossOrigin: &#x27;&#x27;,
    params: {&#x27;LAYERS&#x27;: &#x27;topp:states&#x27;, &#x27;TILED&#x27;: true},
    serverType: &#x27;geoserver&#x27;,
    tileGrid: new ol.tilegrid.TileGrid({
      extent: [-13884991, 2870341, -7455066, 6338219],
      resolutions: resolutions,
      tileSize: [512, 256]
    }),
    projection: &#x27;EPSG:3857&#x27;
  })
});


var map &#x3D; new ol.Map({
  layers: [
    layers[&#x27;mapquest&#x27;],
    layers[&#x27;bng&#x27;]
  ],
  target: &#x27;map&#x27;,
  view: new ol.View({
    projection: &#x27;EPSG:3857&#x27;,
    center: [0, 0],
    zoom: 2
  })
});


var baseLayerSelect &#x3D; document.getElementById(&#x27;base-layer&#x27;);
var overlayLayerSelect &#x3D; document.getElementById(&#x27;overlay-layer&#x27;);
var viewProjSelect &#x3D; document.getElementById(&#x27;view-projection&#x27;);
var renderEdgesCheckbox &#x3D; document.getElementById(&#x27;render-edges&#x27;);
var renderEdges &#x3D; false;

function updateViewProjection() {
  var newProj &#x3D; ol.proj.get(viewProjSelect.value);
  var newProjExtent &#x3D; newProj.getExtent();
  var newView &#x3D; new ol.View({
    projection: newProj,
    center: ol.extent.getCenter(newProjExtent || [0, 0, 0, 0]),
    zoom: 0,
    extent: newProjExtent || undefined
  });
  map.setView(newView);

  // Example how to prevent double occurence of map by limiting layer extent
  if (newProj &#x3D;&#x3D; ol.proj.get(&#x27;EPSG:3857&#x27;)) {
    layers[&#x27;bng&#x27;].setExtent([-1057216, 6405988, 404315, 8759696]);
  } else {
    layers[&#x27;bng&#x27;].setExtent(undefined);
  }
}


/**
 * @param {Event} e Change event.
 */
viewProjSelect.onchange &#x3D; function(e) {
  updateViewProjection();
};

updateViewProjection();

var updateRenderEdgesOnLayer &#x3D; function(layer) {
  if (layer instanceof ol.layer.Tile) {
    var source &#x3D; layer.getSource();
    if (source instanceof ol.source.TileImage) {
      source.setRenderReprojectionEdges(renderEdges);
    }
  }
};


/**
 * @param {Event} e Change event.
 */
baseLayerSelect.onchange &#x3D; function(e) {
  var layer &#x3D; layers[baseLayerSelect.value];
  if (layer) {
    layer.setOpacity(1);
    updateRenderEdgesOnLayer(layer);
    map.getLayers().setAt(0, layer);
  }
};


/**
 * @param {Event} e Change event.
 */
overlayLayerSelect.onchange &#x3D; function(e) {
  var layer &#x3D; layers[overlayLayerSelect.value];
  if (layer) {
    layer.setOpacity(0.7);
    updateRenderEdgesOnLayer(layer);
    map.getLayers().setAt(1, layer);
  }
};


/**
 * @param {Event} e Change event.
 */
renderEdgesCheckbox.onchange &#x3D; function(e) {
  renderEdges &#x3D; renderEdgesCheckbox.checked;
  map.getLayers().forEach(function(layer) {
    updateRenderEdgesOnLayer(layer);
  });
};
</textarea>
          <textarea class="hidden" name="css"></textarea>
          <textarea class="hidden" name="html">&lt;div class&#x3D;&quot;row-fluid&quot;&gt;
  &lt;div class&#x3D;&quot;span12&quot;&gt;
    &lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;form class&#x3D;&quot;form-inline&quot;&gt;
    &lt;div class&#x3D;&quot;col-md-3&quot;&gt;
      &lt;label&gt;Base map:&lt;/label&gt;
      &lt;select id&#x3D;&quot;base-layer&quot;&gt;
        &lt;option value&#x3D;&quot;mapquest&quot;&gt;MapQuest (EPSG:3857)&lt;/option&gt;
        &lt;option value&#x3D;&quot;wms4326&quot;&gt;WMS (EPSG:4326)&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;div class&#x3D;&quot;col-md-4&quot;&gt;
      &lt;label&gt;Overlay map:&lt;/label&gt;
      &lt;select id&#x3D;&quot;overlay-layer&quot;&gt;
        &lt;option value&#x3D;&quot;bng&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
        &lt;option value&#x3D;&quot;wms21781&quot;&gt;Swisstopo WMS (EPSG:21781)&lt;/option&gt;
        &lt;option value&#x3D;&quot;wmts3413&quot;&gt;NASA Arctic WMTS (EPSG:3413)&lt;/option&gt;
        &lt;option value&#x3D;&quot;grandcanyon&quot;&gt;Grand Canyon HiDPI (EPSG:3857)&lt;/option&gt;
        &lt;option value&#x3D;&quot;states&quot;&gt;United States (EPSG:3857)&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;div class&#x3D;&quot;col-md-5&quot;&gt;
      &lt;label&gt;View projection:&lt;/label&gt;
      &lt;select id&#x3D;&quot;view-projection&quot;&gt;
        &lt;option value&#x3D;&quot;EPSG:3857&quot;&gt;Spherical Mercator (EPSG:3857)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:4326&quot;&gt;WGS 84 (EPSG:4326)&lt;/option&gt;
        &lt;option value&#x3D;&quot;ESRI:54009&quot;&gt;Mollweide (ESRI:54009)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:27700&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:23032&quot;&gt;ED50 / UTM zone 32N (EPSG:23032)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:2163&quot;&gt;US National Atlas Equal Area (EPSG:2163)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:3413&quot;&gt;NSIDC Polar Stereographic North (EPSG:3413)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:5479&quot;&gt;RSRGD2000 / MSLC2000 (EPSG:5479)&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;label for&#x3D;&quot;render-edges&quot;&gt;&lt;input type&#x3D;&quot;checkbox&quot; id&#x3D;&quot;render-edges&quot; /&gt;Render reprojection edges&lt;/label&gt; (only displayed on reprojected data)
  &lt;/form&gt;
&lt;/div&gt;
</textarea>
          <input type="hidden" name="wrap" value="l">
          <input type="hidden" name="resources" value="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css,https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js,http://openlayers.org/en/v3.11.1/css/ol.css,http://openlayers.org/en/v3.11.1/build/ol.js,http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js">
        </form>
        <pre><code id="example-source" class="language-markup">&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Raster reprojection example&lt;/title&gt;
&lt;script src="https://code.jquery.com/jquery-1.11.2.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"&gt;
&lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" href="http://openlayers.org/en/v3.11.1/css/ol.css" type="text/css"&gt;
&lt;script src="http://openlayers.org/en/v3.11.1/build/ol.js"&gt;&lt;/script&gt;
&lt;script src&#x3D;&quot;http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.6/proj4.js&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div class="container-fluid"&gt;

&lt;div class&#x3D;&quot;row-fluid&quot;&gt;
  &lt;div class&#x3D;&quot;span12&quot;&gt;
    &lt;div id&#x3D;&quot;map&quot; class&#x3D;&quot;map&quot;&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;form class&#x3D;&quot;form-inline&quot;&gt;
    &lt;div class&#x3D;&quot;col-md-3&quot;&gt;
      &lt;label&gt;Base map:&lt;/label&gt;
      &lt;select id&#x3D;&quot;base-layer&quot;&gt;
        &lt;option value&#x3D;&quot;mapquest&quot;&gt;MapQuest (EPSG:3857)&lt;/option&gt;
        &lt;option value&#x3D;&quot;wms4326&quot;&gt;WMS (EPSG:4326)&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;div class&#x3D;&quot;col-md-4&quot;&gt;
      &lt;label&gt;Overlay map:&lt;/label&gt;
      &lt;select id&#x3D;&quot;overlay-layer&quot;&gt;
        &lt;option value&#x3D;&quot;bng&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
        &lt;option value&#x3D;&quot;wms21781&quot;&gt;Swisstopo WMS (EPSG:21781)&lt;/option&gt;
        &lt;option value&#x3D;&quot;wmts3413&quot;&gt;NASA Arctic WMTS (EPSG:3413)&lt;/option&gt;
        &lt;option value&#x3D;&quot;grandcanyon&quot;&gt;Grand Canyon HiDPI (EPSG:3857)&lt;/option&gt;
        &lt;option value&#x3D;&quot;states&quot;&gt;United States (EPSG:3857)&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;div class&#x3D;&quot;col-md-5&quot;&gt;
      &lt;label&gt;View projection:&lt;/label&gt;
      &lt;select id&#x3D;&quot;view-projection&quot;&gt;
        &lt;option value&#x3D;&quot;EPSG:3857&quot;&gt;Spherical Mercator (EPSG:3857)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:4326&quot;&gt;WGS 84 (EPSG:4326)&lt;/option&gt;
        &lt;option value&#x3D;&quot;ESRI:54009&quot;&gt;Mollweide (ESRI:54009)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:27700&quot;&gt;British National Grid (EPSG:27700)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:23032&quot;&gt;ED50 / UTM zone 32N (EPSG:23032)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:2163&quot;&gt;US National Atlas Equal Area (EPSG:2163)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:3413&quot;&gt;NSIDC Polar Stereographic North (EPSG:3413)&lt;/option&gt;
        &lt;option value&#x3D;&quot;EPSG:5479&quot;&gt;RSRGD2000 / MSLC2000 (EPSG:5479)&lt;/option&gt;
      &lt;/select&gt;
    &lt;/div&gt;
    &lt;label for&#x3D;&quot;render-edges&quot;&gt;&lt;input type&#x3D;&quot;checkbox&quot; id&#x3D;&quot;render-edges&quot; /&gt;Render reprojection edges&lt;/label&gt; (only displayed on reprojected data)
  &lt;/form&gt;
&lt;/div&gt;

&lt;/div&gt;
&lt;script&gt;
proj4.defs(&#x27;EPSG:27700&#x27;, &#x27;+proj&#x3D;tmerc +lat_0&#x3D;49 +lon_0&#x3D;-2 +k&#x3D;0.9996012717 &#x27; +
    &#x27;+x_0&#x3D;400000 +y_0&#x3D;-100000 +ellps&#x3D;airy &#x27; +
    &#x27;+towgs84&#x3D;446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 &#x27; +
    &#x27;+units&#x3D;m +no_defs&#x27;);
var proj27700 &#x3D; ol.proj.get(&#x27;EPSG:27700&#x27;);
proj27700.setExtent([0, 0, 700000, 1300000]);

proj4.defs(&#x27;EPSG:23032&#x27;, &#x27;+proj&#x3D;utm +zone&#x3D;32 +ellps&#x3D;intl &#x27; +
    &#x27;+towgs84&#x3D;-87,-98,-121,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj23032 &#x3D; ol.proj.get(&#x27;EPSG:23032&#x27;);
proj23032.setExtent([-1206118.71, 4021309.92, 1295389.00, 8051813.28]);

proj4.defs(&#x27;EPSG:5479&#x27;, &#x27;+proj&#x3D;lcc +lat_1&#x3D;-76.66666666666667 +lat_2&#x3D;&#x27; +
    &#x27;-79.33333333333333 +lat_0&#x3D;-78 +lon_0&#x3D;163 +x_0&#x3D;7000000 +y_0&#x3D;5000000 &#x27; +
    &#x27;+ellps&#x3D;GRS80 +towgs84&#x3D;0,0,0,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj5479 &#x3D; ol.proj.get(&#x27;EPSG:5479&#x27;);
proj5479.setExtent([6825737.53, 4189159.80, 9633741.96, 5782472.71]);

proj4.defs(&#x27;EPSG:21781&#x27;, &#x27;+proj&#x3D;somerc +lat_0&#x3D;46.95240555555556 &#x27; +
    &#x27;+lon_0&#x3D;7.439583333333333 +k_0&#x3D;1 +x_0&#x3D;600000 +y_0&#x3D;200000 +ellps&#x3D;bessel &#x27; +
    &#x27;+towgs84&#x3D;674.4,15.1,405.3,0,0,0,0 +units&#x3D;m +no_defs&#x27;);
var proj21781 &#x3D; ol.proj.get(&#x27;EPSG:21781&#x27;);
proj21781.setExtent([485071.54, 75346.36, 828515.78, 299941.84]);

proj4.defs(&#x27;EPSG:3413&#x27;, &#x27;+proj&#x3D;stere +lat_0&#x3D;90 +lat_ts&#x3D;70 +lon_0&#x3D;-45 +k&#x3D;1 &#x27; +
    &#x27;+x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 +units&#x3D;m +no_defs&#x27;);
var proj3413 &#x3D; ol.proj.get(&#x27;EPSG:3413&#x27;);
proj3413.setExtent([-4194304, -4194304, 4194304, 4194304]);

proj4.defs(&#x27;EPSG:2163&#x27;, &#x27;+proj&#x3D;laea +lat_0&#x3D;45 +lon_0&#x3D;-100 +x_0&#x3D;0 +y_0&#x3D;0 &#x27; +
    &#x27;+a&#x3D;6370997 +b&#x3D;6370997 +units&#x3D;m +no_defs&#x27;);
var proj2163 &#x3D; ol.proj.get(&#x27;EPSG:2163&#x27;);
proj2163.setExtent([-8040784.5135, -2577524.9210, 3668901.4484, 4785105.1096]);

proj4.defs(&#x27;ESRI:54009&#x27;, &#x27;+proj&#x3D;moll +lon_0&#x3D;0 +x_0&#x3D;0 +y_0&#x3D;0 +datum&#x3D;WGS84 &#x27; +
    &#x27;+units&#x3D;m +no_defs&#x27;);
var proj54009 &#x3D; ol.proj.get(&#x27;ESRI:54009&#x27;);
proj54009.setExtent([-18e6, -9e6, 18e6, 9e6]);


var layers &#x3D; [];

layers[&#x27;bng&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.XYZ({
    projection: &#x27;EPSG:27700&#x27;,
    url: &#x27;http://tileserver.maptiler.com/miniscale/{z}/{x}/{y}.png&#x27;,
    crossOrigin: &#x27;&#x27;,
    maxZoom: 6
  })
});

layers[&#x27;mapquest&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.MapQuest({layer: &#x27;osm&#x27;})
});

layers[&#x27;wms4326&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: &#x27;http://demo.boundlessgeo.com/geoserver/wms&#x27;,
    crossOrigin: &#x27;&#x27;,
    params: {
      &#x27;LAYERS&#x27;: &#x27;ne:NE1_HR_LC_SR_W_DR&#x27;
    },
    projection: &#x27;EPSG:4326&#x27;
  })
});

layers[&#x27;wms21781&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    attributions: [new ol.Attribution({
      html: &#x27;&amp;copy; &#x27; +
          &#x27;&lt;a href&#x3D;&quot;http://www.geo.admin.ch/internet/geoportal/&#x27; +
          &#x27;en/home.html&quot;&gt;&#x27; +
          &#x27;Pixelmap 1:1000000 / geo.admin.ch&lt;/a&gt;&#x27;
    })],
    crossOrigin: &#x27;anonymous&#x27;,
    params: {
      &#x27;LAYERS&#x27;: &#x27;ch.swisstopo.pixelkarte-farbe-pk1000.noscale&#x27;,
      &#x27;FORMAT&#x27;: &#x27;image/jpeg&#x27;
    },
    url: &#x27;http://wms.geo.admin.ch/&#x27;,
    projection: &#x27;EPSG:21781&#x27;
  })
});

var parser &#x3D; new ol.format.WMTSCapabilities();
$.ajax(&#x27;http://map1.vis.earthdata.nasa.gov/wmts-arctic/&#x27; +
    &#x27;wmts.cgi?SERVICE&#x3D;WMTS&amp;request&#x3D;GetCapabilities&#x27;).then(function(response) {
  var result &#x3D; parser.read(response);
  var options &#x3D; ol.source.WMTS.optionsFromCapabilities(result,
      {layer: &#x27;OSM_Land_Mask&#x27;, matrixSet: &#x27;EPSG3413_250m&#x27;});
  options.crossOrigin &#x3D; &#x27;&#x27;;
  options.projection &#x3D; &#x27;EPSG:3413&#x27;;
  options.wrapX &#x3D; false;
  layers[&#x27;wmts3413&#x27;] &#x3D; new ol.layer.Tile({
    source: new ol.source.WMTS(options)
  });
});

layers[&#x27;grandcanyon&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.XYZ({
    url: &#x27;http://tileserver.maptiler.com/grandcanyon@2x/{z}/{x}/{y}.png&#x27;,
    crossOrigin: &#x27;&#x27;,
    tilePixelRatio: 2,
    maxZoom: 15,
    attributions: [new ol.Attribution({
      html: &#x27;Tiles &amp;copy; USGS, rendered with &#x27; +
          &#x27;&lt;a href&#x3D;&quot;http://www.maptiler.com/&quot;&gt;MapTiler&lt;/a&gt;&#x27;
    })]
  })
});

var startResolution &#x3D;
    ol.extent.getWidth(ol.proj.get(&#x27;EPSG:3857&#x27;).getExtent()) / 256;
var resolutions &#x3D; new Array(22);
for (var i &#x3D; 0, ii &#x3D; resolutions.length; i &lt; ii; ++i) {
  resolutions[i] &#x3D; startResolution / Math.pow(2, i);
}

layers[&#x27;states&#x27;] &#x3D; new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: &#x27;http://demo.boundlessgeo.com/geoserver/wms&#x27;,
    crossOrigin: &#x27;&#x27;,
    params: {&#x27;LAYERS&#x27;: &#x27;topp:states&#x27;, &#x27;TILED&#x27;: true},
    serverType: &#x27;geoserver&#x27;,
    tileGrid: new ol.tilegrid.TileGrid({
      extent: [-13884991, 2870341, -7455066, 6338219],
      resolutions: resolutions,
      tileSize: [512, 256]
    }),
    projection: &#x27;EPSG:3857&#x27;
  })
});


var map &#x3D; new ol.Map({
  layers: [
    layers[&#x27;mapquest&#x27;],
    layers[&#x27;bng&#x27;]
  ],
  target: &#x27;map&#x27;,
  view: new ol.View({
    projection: &#x27;EPSG:3857&#x27;,
    center: [0, 0],
    zoom: 2
  })
});


var baseLayerSelect &#x3D; document.getElementById(&#x27;base-layer&#x27;);
var overlayLayerSelect &#x3D; document.getElementById(&#x27;overlay-layer&#x27;);
var viewProjSelect &#x3D; document.getElementById(&#x27;view-projection&#x27;);
var renderEdgesCheckbox &#x3D; document.getElementById(&#x27;render-edges&#x27;);
var renderEdges &#x3D; false;

function updateViewProjection() {
  var newProj &#x3D; ol.proj.get(viewProjSelect.value);
  var newProjExtent &#x3D; newProj.getExtent();
  var newView &#x3D; new ol.View({
    projection: newProj,
    center: ol.extent.getCenter(newProjExtent || [0, 0, 0, 0]),
    zoom: 0,
    extent: newProjExtent || undefined
  });
  map.setView(newView);

  // Example how to prevent double occurence of map by limiting layer extent
  if (newProj &#x3D;&#x3D; ol.proj.get(&#x27;EPSG:3857&#x27;)) {
    layers[&#x27;bng&#x27;].setExtent([-1057216, 6405988, 404315, 8759696]);
  } else {
    layers[&#x27;bng&#x27;].setExtent(undefined);
  }
}


/**
 * @param {Event} e Change event.
 */
viewProjSelect.onchange &#x3D; function(e) {
  updateViewProjection();
};

updateViewProjection();

var updateRenderEdgesOnLayer &#x3D; function(layer) {
  if (layer instanceof ol.layer.Tile) {
    var source &#x3D; layer.getSource();
    if (source instanceof ol.source.TileImage) {
      source.setRenderReprojectionEdges(renderEdges);
    }
  }
};


/**
 * @param {Event} e Change event.
 */
baseLayerSelect.onchange &#x3D; function(e) {
  var layer &#x3D; layers[baseLayerSelect.value];
  if (layer) {
    layer.setOpacity(1);
    updateRenderEdgesOnLayer(layer);
    map.getLayers().setAt(0, layer);
  }
};


/**
 * @param {Event} e Change event.
 */
overlayLayerSelect.onchange &#x3D; function(e) {
  var layer &#x3D; layers[overlayLayerSelect.value];
  if (layer) {
    layer.setOpacity(0.7);
    updateRenderEdgesOnLayer(layer);
    map.getLayers().setAt(1, layer);
  }
};


/**
 * @param {Event} e Change event.
 */
renderEdgesCheckbox.onchange &#x3D; function(e) {
  renderEdges &#x3D; renderEdgesCheckbox.checked;
  map.getLayers().forEach(function(layer) {
    updateRenderEdgesOnLayer(layer);
  });
};

&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</code></pre>
      </div>
    </div>

    <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="./resources/common.js"></script>
    <script src="./resources/prism/prism.min.js"></script>
    <script src="loader.js?id=reprojection"></script>

  </body>
</html>
